package com.wy.fragments;

import java.util.List;

import com.wy.adapter.MusicAdapter;
import com.wy.domain.Music;
import com.wy.music_player.MusicPlayerActivity;
import com.wy.music_player.R;
import com.wy.utils.MusicList;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class SongsFragment extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		final View view = inflater.inflate(R.layout.songs_layout, container, false);

		ListView listView = (ListView) view.findViewById(R.id.listView1);
		List<Music> listMusic = MusicList
				.getAllMusicData(view.getContext());
		MusicAdapter adapter = new MusicAdapter(view.getContext(), listMusic);
		listView.setAdapter(adapter);

		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int id,
					long arg3) {
				// TODO Auto-generated method stub
				Intent it = new Intent(view.getContext(),
						MusicPlayerActivity.class);
				it.putExtra("id", id);
				startActivity(it);
			}
		});
		return view;
	}
}
